home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk7 / blitlab3 / bits.c next >
C/C++ Source or Header  |  1995-03-18  |  3KB  |  132 lines

  1. /*
  2.  *   This routine handles the display of the bit array in BlitLab.
  3.  */
  4. #include "structures.h"
  5. /*
  6.  *   This is the address of the real bits we operate on.
  7.  */
  8. extern short int *realbits ;
  9. extern long gvals[] ;
  10. static short safearr[192] ;
  11. static short osafearr[192] ;
  12. static int specbits ; /* should we leave the undo array alone? */
  13. allocbitmem() {
  14.    extern void *allocmem() ;
  15.  
  16.    realbits = (short *)(allocmem(1000L, MEMF_CHIP | MEMF_CLEAR)) + 150 ;
  17. }
  18. pdot(x, y, on)
  19. int x, y, on ;
  20. {
  21.    int off = (x >> 4) + y * 6 ;
  22.    int bit = 1 << (15 - (x & 15)) ;
  23.  
  24.    if (on) {
  25.       if ((realbits[off] & bit) == 0) {
  26.          realbits[off] |= bit ;
  27.          safearr[off] |= bit ;
  28.          color(WHITE) ;
  29.          fbox(x * 6 + HBITSTART, y * 3 + VBITSTART + 1, 4, 2) ;
  30.       }
  31.    } else {
  32.       if (realbits[off] & bit) {
  33.          realbits[off] &= ~bit ;
  34.          safearr[off] &= ~bit ;
  35.          color(BLACK) ;
  36.          fbox(x * 6 + HBITSTART, y * 3 + VBITSTART + 1, 4, 2) ;
  37.       }
  38.    }
  39. }
  40. preg(x1, y1, x2, y2, on)
  41. int x1, y1, x2, y2, on ;
  42. {
  43.    int i, j ;
  44.  
  45.    for (i=x1; i<=x2; i++)
  46.       for (j=y1; j<=y2; j++)
  47.          pdot(i, j, on) ;
  48. }
  49. /*
  50.  *   This routine writes out the new position to the screen.
  51.  */
  52. updatepos(x1, y1)
  53. int x1, y1 ;
  54. {
  55.    char outbuf[4] ;
  56.  
  57.    sprintf(outbuf, "%3d", ((x1 >> 3) & ~1) + y1 * 12) ;
  58.    drawtext(HLMGSTART+28, VLMG3+10, outbuf) ;
  59.    sprintf(outbuf, "%2d", x1 & 15) ;
  60.    drawtext(HLMGSTART+20, VLMG3+26, outbuf) ;
  61. }
  62. undobits() {
  63.    register short *p2 = osafearr, *p3 = realbits ;
  64.    int i = 192 ;
  65.  
  66.    while (i-- > 0)
  67.       *p3++ = *p2++ ;
  68.    updatebits() ;
  69. }
  70. updatebits() {
  71.    int x=HBITSTART, y=VBITSTART+1 ;
  72.    register short *p1 = realbits, *p2 = safearr, *p3 = osafearr ;
  73.    int i = 192 ;
  74.    int rc = 6 ;
  75.    int bit ;
  76.  
  77.    while (i-- > 0) {
  78.       *p3++ = *p2 ;
  79.       if (*p1 == *p2) {
  80.          p1++ ;
  81.          p2++ ;
  82.          x += 6 * 16 ;
  83.       } else {
  84.          if (!specbits) {
  85.             bit = 0x8000 ;
  86.             while (bit != 0) {
  87.                if ((*p2 & bit) != (*p1 & bit)) {
  88.                   color((*p1 & bit) ? WHITE : BLACK) ;
  89.                   fbox(x, y, 4, 2) ;
  90.                }
  91.                bit = (bit >> 1) & 0x7fff ;
  92.                x += 6 ;
  93.             }
  94.          } else
  95.             x += 6 * 16 ;
  96.          *p2++ = *p1++ ;
  97.       }
  98.       if (--rc == 0) {
  99.          rc = 6 ;
  100.          x = HBITSTART ;
  101.          y += 3 ;
  102.       }
  103.    }
  104.    specbits = 0 ;
  105. }
  106. /*
  107.  *   Here we update a single screen word, if it lies on the screen.
  108.  */
  109. screenupdate(where, what)
  110. short *where ;
  111. short what ;
  112. {
  113.    int i, bit, x, y ;
  114.  
  115.    specbits = 1 ;
  116.    if (where >= realbits && where < realbits + 192) {
  117.       i = where - realbits ;
  118.       y = VBITSTART + 1 + (i / 6) * 3 ;
  119.       x = HBITSTART + (i % 6) * 96 ;
  120.       for (bit=0x8000; bit != 0; bit = (bit >> 1) & 0x7fff, x += 6) {
  121.          if ((bit & what) != (bit & *where)) {
  122.             color((what & bit) ? WHITE : BLACK) ;
  123.             fbox(x, y, 4, 2) ;
  124.          }
  125.       }
  126.       *where = what ;
  127.    } else {
  128.       error("Dangerous assignment!") ;
  129.       Delay(25L) ;
  130.    }
  131. }
  132.